package com.hmdp.Rabbitmq;

import com.hmdp.entity.VoucherOrder;
import com.hmdp.service.impl.VoucherOrderServiceImpl;
import com.hmdp.utils.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MQReceiver {
    @Autowired
    private VoucherOrderServiceImpl voucherOrderService;

    @RabbitListener(queues = "seckillQueue")
    public void receive(String msg){
        log.info("接收消息：" + msg);
        VoucherOrder voucherOrder = JsonUtil.jsonStr2Object(msg, VoucherOrder.class);
        voucherOrderService.createVoucherOrder(voucherOrder);
    }
}
